package com.goldstone.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import org.hibernate.annotations.IndexColumn;

@Entity
public class Pack extends IdEntity{
	private List<ColorSize> colorSizes;
	private String type;
	private Integer packNum;
	
	private Integer length;
	private Integer width;
	private Integer height;
	
	private Float weight;

	public Pack(String type) {
		this.type = type;
	}
	public Pack(String type, List<ColorSize> colorSizes) {
		this.type = type;
		this.colorSizes = colorSizes;
	}
	
	@ElementCollection(targetClass = ColorSize.class)
	@JoinTable(name = "COLOR_SIZE", joinColumns = {@JoinColumn(name = "PACK_ID")})
	@IndexColumn(name = "linenum")
	public List<ColorSize> getColorSizes() {
		return colorSizes;
	}
	public void setColorSizes(List<ColorSize> colorSizes) {
		this.colorSizes = colorSizes;
	}
	
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	
	public Integer getPackNum() {
		return packNum;
	}
	public void setPackNum(Integer packNum) {
		this.packNum = packNum;
	}
	public Integer getLength() {
		return length;
	}
	public void setLength(Integer length) {
		this.length = length;
	}
	public Integer getWidth() {
		return width;
	}
	public void setWidth(Integer width) {
		this.width = width;
	}
	public Integer getHeight() {
		return height;
	}
	public void setHeight(Integer height) {
		this.height = height;
	}
	public Float getWeight() {
		return weight;
	}
	public void setWeight(Float weight) {
		this.weight = weight;
	}
	@Transient
	public Integer getVolume() {
		return length * width * height; 
	}
	
	public void setVolume(Integer length, Integer width, Integer height) {
		this.length = length;
		this.width = width;
		this.height = height;
	}
	
	@Transient
	public Integer getTotal() {
		Integer total = 0;
		for(ColorSize cs : colorSizes) {
			total += cs.getNum();
		}
		return total * packNum;
	}
}
